package com.zhijian.medical.service.impl;

import com.zhijian.medical.dao.local.AgentiaCategoryVerifyRecordMapper;
import com.zhijian.medical.entity.po.AgentiaCategoryVerifyRecord;
import com.zhijian.medical.entity.vo.request.AgentiaCategoryVerifyRecordSearchVo;
import com.zhijian.medical.entity.vo.response.AgentiaCategoryVerifyRecordVo;
import com.zhijian.medical.service.AgentiaCategoryVerifyRecordService;
import com.zhijian.medical.util.Page;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * 验证记录业务处理层
 *
 * @author HCG
 * @date 2022-01-14 21:08:37
 * @version: 1.0
 */
@Slf4j
@Service
public class AgentiaCategoryVerifyRecordServiceImpl implements AgentiaCategoryVerifyRecordService {

    @Autowired
    private AgentiaCategoryVerifyRecordMapper mapper;

    @Override
    public AgentiaCategoryVerifyRecord selectById(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public AgentiaCategoryVerifyRecordVo selectVoById(Long id) {
        return mapper.selectVoById(id);
    }

    @Override
    public void deleteById(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public Long insert(AgentiaCategoryVerifyRecord agentiaCategoryVerifyRecord) {
        Date now = new Date();
        agentiaCategoryVerifyRecord.setCreateTime(now);
        agentiaCategoryVerifyRecord.setUpdateTime(now);
        return mapper.insert(agentiaCategoryVerifyRecord) == 1 ? agentiaCategoryVerifyRecord.getId() : 0L;
    }

    @Override
    public boolean update(AgentiaCategoryVerifyRecord agentiaCategoryVerifyRecord) {
        Date now = new Date();
        agentiaCategoryVerifyRecord.setUpdateTime(now);
        return mapper.updateByPrimaryKey(agentiaCategoryVerifyRecord) != 0;
    }

    @Override
    public Integer count(AgentiaCategoryVerifyRecordSearchVo agentiaCategoryVerifyRecordSearchVo) {
        return mapper.count(agentiaCategoryVerifyRecordSearchVo);
    }

    @Override
    public List<AgentiaCategoryVerifyRecordVo> selectList(AgentiaCategoryVerifyRecordSearchVo agentiaCategoryVerifyRecordSearchVo) {
        return mapper.selectList(agentiaCategoryVerifyRecordSearchVo);
    }

    @Override
    public Page<AgentiaCategoryVerifyRecordVo> selectPage(AgentiaCategoryVerifyRecordSearchVo agentiaCategoryVerifyRecordSearchVo) {
        //先直接查总数
        int count = count(agentiaCategoryVerifyRecordSearchVo);
        //分页
        Page<AgentiaCategoryVerifyRecordVo> page = new Page<>(true, count, agentiaCategoryVerifyRecordSearchVo.getPageNum(), agentiaCategoryVerifyRecordSearchVo.getPageSize());
        agentiaCategoryVerifyRecordSearchVo.setStartIndex(page.getStartIndex());
        page.setPage(true);
        page.setTotalCount(count);
        List<AgentiaCategoryVerifyRecordVo> responseVos = this.selectList(agentiaCategoryVerifyRecordSearchVo);
        page.setData(responseVos);
        return page;
    }

}